package com.grupoconstruobras.sigo.exhumaciones.ui.datamodel;

import com.grupoconstruobras.sigo.datatransfer.ResultSet;

import java.util.List;

import javax.faces.context.FacesContext;

import org.richfaces.model.Arrangeable;
import org.richfaces.model.ArrangeableState;

public abstract class ExtendedDataModel<T> extends org.ajax4jsf.model.ExtendedDataModel<T> implements Arrangeable {
	
	protected List<T> rows;
	protected int count;
	protected ArrangeableState arrangeableState;
	protected Object rowKey;
	protected IQueryBuilder builder;
	
	public ExtendedDataModel(IQueryBuilder builder) {
		super();
		this.builder = builder;
	}
	
	@Override
	public void arrange(FacesContext context, ArrangeableState arrangeableState) {
			this.arrangeableState = arrangeableState;
			builder.setArrangeableState(arrangeableState);
	}
	
	public ResultSet<T> getResult() {
		return new ResultSet<T>(count, rows);
	}
	
	@Override
	public void setRowKey(Object key) {
		rowKey = key;
	}

	@Override
	public Object getRowKey() {
		return rowKey;
	}
	
	@Override
	public boolean isRowAvailable() {
		return rowKey != null;
	}
	
	@Override
	public int getRowIndex() {
		return -1;
	}

	@Override
	public void setRowIndex(int rowIndex) {
		throw new UnsupportedOperationException();
	}

	@Override
	public Object getWrappedData() {
		throw new UnsupportedOperationException();
	}

	@Override
	public void setWrappedData(Object data) {
		throw new UnsupportedOperationException();
	}

}
